home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / moden / tcom / batchul.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-08  |  5.2 KB  |  208 lines

  1. {$G+,X+}
  2.  
  3. {Conditional defines that may affect this unit}
  4. {$I AWDEFINE.INC}
  5.  
  6. {*********************************************************}
  7. {*                   BATCHUL.PAS 1.01                    *}
  8. {*        Copyright (c) TurboPower Software 1995         *}
  9. {*                 All rights reserved.                  *}
  10. {*********************************************************}
  11.  
  12. unit Batchul;
  13.  
  14. interface
  15.  
  16. uses
  17.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  18.   Forms, Dialogs, StdCtrls, FileCtrl, Buttons, AdMisc, TComIni;
  19.  
  20. type
  21.   TBatchUploadForm = class(TForm)
  22.     FileList: TFileListBox;
  23.     DirList: TDirectoryListBox;
  24.     GroupBox1: TGroupBox;
  25.     Label1: TLabel;
  26.     Label2: TLabel;
  27.     DirLabel: TLabel;
  28.     MaskEdit: TEdit;
  29.     DriveBox: TDriveComboBox;
  30.     OutgoingList: TListBox;
  31.     Label4: TLabel;
  32.     OkBtn: TBitBtn;
  33.     CancelBtn: TBitBtn;
  34.     HelpBtn: TBitBtn;
  35.     AddBtn: TBitBtn;
  36.     RemoveBtn: TBitBtn;
  37.     procedure FileListDblClick(Sender: TObject);
  38.     procedure OkBtnClick(Sender: TObject);
  39.     procedure AddBtnClick(Sender: TObject);
  40.     procedure RemoveBtnClick(Sender: TObject);
  41.     procedure OutgoingListDblClick(Sender: TObject);
  42.  
  43.   private
  44.     OutList : TStrings;
  45.  
  46.     function FileInOutgoing(const FName : String) : Boolean;
  47.       {-Return TRUE if FName is in the outgoing file list}
  48.  
  49.   public
  50.     constructor Create(AOwner : TComponent; AFileList : TStrings);
  51.   end;
  52.  
  53. implementation
  54.  
  55. {$R *.DFM}
  56.  
  57. function ContainsWildCards(const S : String) : Boolean;
  58. var
  59.   I : Word;
  60.  
  61. begin
  62.   Result := True;
  63.   for I := 1 to Length(S) do
  64.     if (S[I] = '*') or (S[I] = '?') then
  65.       Exit;
  66.   Result := False;
  67. end;
  68.  
  69. constructor TBatchUploadForm.Create(AOwner : TComponent; AFileList : TStrings);
  70. var
  71.   Path : String;
  72.  
  73. begin
  74.   inherited Create(AOwner);
  75.  
  76.   OutList := AFileList;
  77.  
  78.   if IsDirectory(UploadDir) then
  79.     Path := FullPathName(AddBackslash(UploadDir) + '*.*')
  80.   else
  81.     Path := '';
  82.  
  83.   MaskEdit.Text        := '';
  84.   DriveBox.Drive       := Path[1];
  85.   DirList.Directory    := JustPathName(Path);
  86. end;
  87.  
  88. function TBatchUploadForm.FileInOutgoing(const FName : String) : Boolean;
  89.   {-Return TRUE if FName is in the outgoing file list}
  90. begin
  91.   Result := (OutgoingList.Items.IndexOf(FName) <> -1);
  92. end;
  93.  
  94. procedure TBatchUploadForm.FileListDblClick(Sender: TObject);
  95. var
  96.   Path : String;
  97.  
  98. begin
  99.   Path := LowerCase(FileList.FileName);
  100.   if (Path = '') then
  101.     Exit;
  102.  
  103.   if not FileInOutgoing(Path) then begin
  104.     OutgoingList.Items.Add(Path);
  105.     OkBtn.Enabled := True;
  106.   end;
  107. end;
  108.  
  109. procedure TBatchUploadForm.OkBtnClick(Sender: TObject);
  110. var
  111.   I : Word;
  112.  
  113. begin
  114.   if (OutgoingList.Items.Count <> 0) then begin
  115.     for I := 0 to Pred(OutgoingList.Items.Count) do
  116.       OutList.Add(OutgoingList.Items[I]);
  117.   end else
  118.     ModalResult := mrNone;
  119. end;
  120.  
  121. procedure TBatchUploadForm.AddBtnClick(Sender: TObject);
  122. var
  123.   I       : Word;
  124.   N       : String;
  125.   TempDir : String;
  126.  
  127. begin
  128.   {if there are any files selected, add those to the outgoing list}
  129.   if not ContainsWildCards(MaskEdit.Text) and (FileList.SelCount <> 0) then begin
  130.     Cursor := crHourGlass;
  131.     for I := 0 to Pred(FileList.Items.Count) do
  132.      if FileList.Selected[I] then
  133.        OutgoingList.Items.Add(LowerCase(AddBackslash(FileList.Directory) + FileList.Items[I]));
  134.     OkBtn.Enabled := True;
  135.     Cursor := crDefault;
  136.   end else begin
  137.     {if nothing's entered, exit the form}
  138.     N := TrimTrail(MaskEdit.Text);
  139.     if (N = '') then begin
  140.       ModalResult := mrOK;
  141.       OkBtnClick(Sender);
  142.       Exit;
  143.     end;
  144.  
  145.     {get the fully qualified name of the file}
  146.     N := LowerCase(ExpandFileName(N));
  147.  
  148.     {extract the directory portion of the filename}
  149.     TempDir := JustPathname(N);
  150.  
  151.     {validate the directory}
  152.     if not IsDirectory(TempDir) then begin
  153.       MessageBeep(0);
  154.       MaskEdit.SetFocus;
  155.       Exit;
  156.     end;
  157.  
  158.     {if the name contains no wildcards, add the file to the outgoing list}
  159.     if not ContainsWildCards(N) then begin
  160.       {make sure the file exists}
  161.       if not FileExists(N) then begin
  162.         MessageBeep(0);
  163.         MaskEdit.SetFocus;
  164.  
  165.       {make sure the file isn't already in the list}
  166.       end else if not FileInOutgoing(N) then begin
  167.         OutgoingList.Items.Add(N);
  168.         MaskEdit.Text := '';
  169.         OkBtn.Enabled := True;
  170.       end;
  171.  
  172.     {the name contains wildcards...reset the directory and mask and}
  173.     {reload the listboxes with the new information                 }
  174.     end else begin
  175.       FileList.Mask     := N;
  176.       DirList.Directory := TempDir;
  177.       MaskEdit.Text     := '';
  178.     end;
  179.   end;
  180. end;
  181.  
  182. procedure TBatchUploadForm.RemoveBtnClick(Sender: TObject);
  183. var
  184.   I : Word;
  185.  
  186. begin
  187.   if (OutgoingList.SelCount = 0) then
  188.     Exit;
  189.  
  190.   Cursor := crHourGlass;
  191.   for I := Pred(OutgoingList.Items.Count) downto 0 do
  192.     if OutgoingList.Selected[I] then
  193.       OutgoingList.Items.Delete(I);
  194.   OkBtn.Enabled := (OutgoingList.Items.Count <> 0);
  195.   Cursor := crDefault;
  196. end;
  197.  
  198. procedure TBatchUploadForm.OutgoingListDblClick(Sender: TObject);
  199. begin
  200.   if (OutgoingList.ItemIndex <> -1) then begin
  201.     OutgoingList.Items.Delete(OutgoingList.ItemIndex);
  202.     OkBtn.Enabled := (OutgoingList.Items.Count <> 0);
  203.   end;
  204. end;
  205.  
  206. end.
  207.  
  208.